﻿using LoveEat.API.Write.Applications.Commands.Goods;
using LoveEat.Domain.Goods;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace LoveEat.API.Write.Applications.CommandHandlers.Goods
{
    public class AddGoodsCreatedCommandHandler : IRequestHandler<AddGoodsCreatedCommand, APIResult<int>>
    {
        private readonly IBaseRespository<GoodsModel> goodsRep;

        public AddGoodsCreatedCommandHandler(IBaseRespository<GoodsModel> goodsRep)
        {
            this.goodsRep = goodsRep;
        }

        public async Task<APIResult<int>> Handle(AddGoodsCreatedCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = APIResultCode.添加成功;
            result.Message = APIResultCode.添加成功.ToString();


            GoodsModel goods = new GoodsModel();
            goods.GoodsNameId = request.GoodsNameId;
            goods.Production = request.Production;
            goods.LifeDay = request.LifeDay;
            goods.Pronumber = request.Pronumber;
            goods.ProCommand = request.ProCommand;
            goods.Path = request.Path;
            goods.Information = request.Information;
            goods.CreateName = request.CreateName;
            goods.CreateTime = DateTime.Now;
            goods.UpdateName = "";
            goods.IsDelete = false;
            goods.AquacultureId = 1;
            goods.slaughterId = 1;
            goods.DeepId = 1;

            await goodsRep.AddAsync(goods);

            return await Task.FromResult(result);
        }
    }
}
